var mask = null;
var count = 1
var login_user = null
var search = null
$(function() { // 初始化内容

	mask = mui.createMask(); //遮罩层
	mui.init();
	tap_init();
	mui('#pullrefresh').pullRefresh({

		up: { //上拉加载
			height: 50, //可选.默认50.触发上拉加载拖动距离
			auto: true, //可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...",
			contentnomore: '没有更多数据了',
			callback: function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				window.setTimeout(function() {
					pullupRefresh()
				}, 500);
			}
		}

	})
	login_user = JSON.parse(localStorage.getItem('loginUser'));
	datetime_init();


})


function pullupRefresh() {

	loadDiscountList();
}

function selectStu() {
	var btnArray = ['取消', '确定'];
	mui.prompt('请输入查询信息', '请输入姓名或电话', new Array('取消', '确定'), function(e) {
		if (e.index == 1) {
			mui.toast(e.value);
			search = e.value;
			count = 1;
			pullupRefresh();

		} else {
			mui.toast('您取消了输入');
		}
	});
}

function recover() {
	search = null;
	count = 1
	pullupRefresh();
}


function tap_init() {


	mui(".mui-scroll").on("tap", ".mui-control-item", function(e) {
		var id = this.getAttribute("data_id");
		console.log(id)

		console.log("跳转")
		window.sessionStorage.setItem("discount_id", id)
		window.location.href = "discount_form.html"
	});


}


function loadDiscountList() {

	var data = {};
	if (search != null) {
		data['search'] = search;
	}
	data['page'] = count;
	data["rows"] = 20;
	data['schoolid'] = login_user.schoolid;
	data["saler"] = login_user.id;
	data['searchrole'] = "ROLE_FX_GW";
	console.log("优惠申请列表上传参数=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "fxgw/yhspGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			count++
			mask.close(); //显示遮罩层 	  
			console.log("记录列表" + JSON.stringify(res));
			app.todos = res.yh_List;
			
		
			//数据加载完成后执行的操作,隐藏加载页面,显示数据
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //停止正在加载
			mui('#pullrefresh').pullRefresh().enablePullupToRefresh(true); //启用上拉加载
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}


var app = new Vue({
	el: '#app',
	data: {
		show: true,
		todos: []
	},
	methods: {

	}
});
